<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>项目管理</title>
    <meta name="description" content="">
    <meta name="author" content="templatemo">
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/templatemo-style.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="js/teacher.js"></script>
    
</head>

<body>
    <!-- Left column -->
    <?php 
    require_once("./system/loginCheck.php"); 
    require_once("../congfig/config.php");
?>
    <div class="templatemo-flex-row">
        <div class="templatemo-sidebar">
            <header class="templatemo-site-header">
                <div class="square"></div>
                <h1>教师管理系统</h1>
            </header>
            <div class="profile-photo-container">
                <img src="images/profile-photo.jpg" alt="Profile Photo" class="img-responsive">
            </div>
            <!-- Search box -->

            <div class="mobile-menu-icon">
                <i class="fa fa-bars"></i>
            </div>
            <nav class="templatemo-left-nav">
                <ul>
                    <li><a href="../index.php"><i class="fa fa-map-marker fa-fw"></i>首页</a></li>
                    <li id="xmgl"><a href="project-list.php"><i class="fa fa-bars fa-fw"></i>我的项目</a> </li>
                    <li id="yhgl"><a href="#" class="active"><i class="fa fa-fire fa-fw"></i>发布项目</a></li>
                    <li id="grxx"><a href="tOwner.php" ><i class=" fa fa-user fa-fw"></i>个人信息</a></li>
                    <li><a href="pad-check.php"><i class="fa fa-cog fa-fw"></i>修改密码</a></li>
                    <li><a href="../loginout.php"><i class="fa fa-map-marker fa-fw"></i>注销</a></li>
                </ul>
            </nav>
        </div>
        <!-- Main content -->
        <?php 
        $uid=$_SESSION["loginflag"];
        $sql="select * from users where uid=$uid";
        $result=$conn->query($sql);
        $row=$result->fetch_array();
         ?>
        <div class="templatemo-content col-1 light-gray-bg" style="height:1000px;">
            <div class="container" style="margin-top:100px;">
                <div class="tab-pane" role="tabpanel" id="addProject">
                    <div style="text-align: right;width: 100%;">
                        <form action="doaddProject.php" method="post" enctype="multipart/form-data" class="form-horizontal">
                            <div class="form-group">
                                <label class="col-xs-4 control-label">项目名称</label>
                                <div class="col-xs-5">
                                    <input type="text" id="pName" name="pName" class="form-control input-sm" style="margin-top: 7px;"><span id="pName_result"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-4 control-label">项目负责人</label>
                                <div class="col-xs-5">
                                    <input type="text" id="pChar" name="pChar" class="form-control input-sm" style="margin-top: 7px;"><span id="pChar_result"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-4 control-label">指导教师</label>
                                <div class="col-xs-5">
                                    <input type="text" readonly="readonly" id="teacher" value="<?php echo $row["username"]?>" name="teacher" class="form-control input-sm" style="margin-top: 7px;">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-4 control-label">项目简介</label>
                                <div class="col-xs-5">
                                    <textarea type="text" id="pDesc" name="pDesc" class="form-control input-sm" style="margin-top: 7px;height: 300px;"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-4 control-label">文件上传</label>
                                <div class="col-xs-5">
                                    <input type="file" name="Enclosure" id="Enclosure" style="margin-top: 7px;" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-4 control-label">项目进度</label>
                                <div class="col-xs-5">
                                    <input type="hidden" id="pRank" name="pRank"  value="0">
                                    <input type="text"class="form-control input-sm" value="申请立项" readonly="true" style="margin-top: 7px;"><span id="pName_result"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-xs-offset-4 col-xs-5" style="margin-left: 169px;">
                                    <input type="submit" id="addProject-bc" class="btn btn-xs btn-success" style="margin-top: 7px;"
                                        value="发布">
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php 
               if (isset($_GET["text"])) {
                  $text=$_GET["text"];
                  echo "<script>alert('$text')</script>";
               } ?>

</body>

</html>
<script type="text/javascript">
        window.onload = function(){

            var pName = document.querySelector("#pName");
            console.log("onload");

            pName.onblur = function(){
                var pNameValue = pName.value;
                console.log("onblur");
                var xhr = null;
                if(window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest();
                } else {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xhr.open("get","./judge_pName.php?pName=" + pNameValue,true);
                console.log(pNameValue);
                xhr.send();
                xhr.onreadystatechange = function(){
                    if(xhr.readyState == 4) {
                        if(xhr.status == 200) {
                            var result = xhr.responseText;
                            console.log(result);

                            var newresult=result.charAt(result.length-1);
                            console.log(newresult);
                            var pName_result = document.querySelector("#pName_result");
                            if(newresult == "0") {
                                pName_result.innerText = "OK";
                            } else if(newresult=="1") {
                                pName_result.innerText = "项目名已经被注册";
                            }
                            else if(newresult=="2"){
                                pName_result.innerText = "项目名不可为空";
                            }

                            else{
                                pName_result.innerText = "hehe ";
                            }
                        }
                    }
                };

            };


            var pChar = document.querySelector("#pChar");
            pChar.onblur = function(){
                var pCharValue = pChar.value;
                console.log("onblur");
                var xhr = null;
                if(window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest();
                } else {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xhr.open("get","./judge_pChar.php?pChar=" + pCharValue,true);
                console.log(pCharValue);
                xhr.send();
                xhr.onreadystatechange = function(){
                    if(xhr.readyState == 4) {
                        if(xhr.status == 200) {
                            var result = xhr.responseText;
                            console.log(result);

                            var newresult=result.charAt(result.length-1);
                            console.log(newresult);
                            var pChar_result = document.querySelector("#pChar_result");
                            if(newresult == "0") {
                                pChar_result.innerText = "查无此人请确认是否已经注册";
                            } else if(newresult=="1") {
                                pChar_result.innerText = "OK";
                            }
                            else if(newresult=="2"){
                                pChar_result.innerText = "项目负责人不可为空";
                            }

                            else{
                                pChar_result.innerText = "hehe ";
                            }
                        }
                    }
                };

            };
        }
        </script>